Dropout ================= 在训练期间对输入张量应用 Dropout 操作。它根据给定的 `mask` 将输入张量中的部分元素置零,并对剩余元素进行缩放。 .. math:: \text{output}_i = \text{input}_i \cdot \text{mask}_i \cdot \text{scale} 输入: - **input** - 输入张量的数据地址。 - **scale** - 缩放因子。 - **length** - 输入张量的总元素数量。 - **mask** - 预先生成的掩码张量的数据地址,其元素为0或1,大小与`input`相同。 - **core_mask** - 核掩码。 输出: - **output** - 输出张量的数据地址,其大小与`input`相同。 支持平台: ``FT78NE`` ``MT7004`` .. note:: - FT78NE 支持fp32 - MT7004 支持fp16, fp32 **共享存储版本:** .. c:function:: void fp_dropout_s(float* input, float scale, int length, float* output, float mask, int core_mask) .. c:function:: void hp_dropout_s(half* input, half scale, int length, half* output, half* mask, int core_mask) **C调用示例:** .. code-block:: c :linenos: :emphasize-lines: 14 //FT78NE示例 #include #include int main(int argc, char* argv[]) { float *input = (float *)0xA0000000; // input 在DDR空间 float *output = (float *)0xB0000000; // output float *mask = (float *)0xC0000000; // pre-generated mask int length = 4096; // 假设 dropout 概率 p = 0.2 float scale = 1.0f / (1.0f - 0.2f); // scale = 1.25 int core_mask = 0xff; fp_dropout_s(input, scale, length, output, mask, core_mask); return 0; } **私有存储版本:** .. c:function:: void fp_dropout_p(float* input, float scale, int length, float* output, float mask) .. c:function:: void hp_dropout_p(half* input, half scale, int length, half* output, half mask) **C调用示例:** .. code-block:: c :linenos: :emphasize-lines: 13 //FT78NE示例 #include #include int main(int argc, char* argv[]) { float *input = (float *)0x10000000; // input 在L2空间 float *output = (float *)0x11000000; // output float *mask = (float *)0x12000000; // pre-generated mask int length = 1024; // 假设 dropout 概率 p = 0.5 float scale = 1.0f / (1.0f - 0.5f); // scale = 2.0 fp_dropout_p(input, scale, length, output, mask); return 0; }